var init = 0
window.onload = (other_aspects) => {
    if (!init) {
        // 初始化暗黑模式
        createRoot()
    }
    init++
    if (typeof other_aspects === 'function') {
        other_aspects()
    }
}

function createRoot() {
    // 给掘金开启暗黑模式
    const Dom = document.getElementsByClassName("Login_ccbox__3N9O7")[0]
    // const Dom = document.getElementsByClassName("timeline-container")[0]
    console.log('Dom==> ', Dom)
    const Button = document.createElement('button')
    Button.id = "BUTTON"
    Button.textContent = '开启暗黑模式'
    Button.addEventListener('click', () => darkLy())

    const Input = document.createElement("input")
    Input.id = 'INPUT'
    Input.type = 'checkbox'
    Input.addEventListener('click', (e) => changStore(e))

    Dom.prepend(Button, Input, "记住我的选择?")
    checkSetting(Input)
}

// 检测是否有记住记录
function checkSetting(dom) {
    chrome.storage.local.get(['enabled'], result => {
        // 检查状态
        // console.log('result ===> ', result)
        if (result.enabled) {
            dom.checked = result.enabled
            darkLy()
        }
    })
}

// 是否记住我的选择
function changStore(e) {
    const setting = {
        enabled: e.target.checked
    }
    // 存放本地
    chrome.storage.local.set(setting, () => {
        console.log('e.target.checked==> ', e.target.checked)
    })
}

// 开启暗黑方法
function darkLy() {
    document.getElementById("root").style.backgroundColor = '#000000'
}